package xyz.hubery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;
import xyz.hubery.domain.Coin;
import xyz.hubery.mapper.CoinMapper;
import xyz.hubery.service.CoinService;
@Service
public class CoinServiceImpl extends ServiceImpl<CoinMapper, Coin> implements CoinService{


    @Override
    public Coin getCoinByName(String coinName) {
        QueryWrapper<Coin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", coinName);
        Coin coin = getOne(queryWrapper);
        return coin;
    }

    @Override
    public List<Coin> findByStatus(Byte status) {
       return list(new LambdaQueryWrapper<Coin>().eq(Coin::getStatus,status));
    }

    @Override
    public Page<Coin> findByPage(Coin coin, Page<Coin> page) {
        LambdaQueryWrapper<Coin> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(coin.getName()),Coin::getName,coin.getName());
        wrapper.like(!StringUtils.isEmpty(coin.getTitle()),Coin::getTitle,coin.getTitle());
        wrapper.eq(!StringUtils.isEmpty(coin.getType()),Coin::getType,coin.getType());
        wrapper.eq(!StringUtils.isEmpty(coin.getWallet()),Coin::getWallet,coin.getWallet());
        wrapper.eq(!StringUtils.isEmpty(coin.getStatus()),Coin::getStatus,coin.getStatus());

        return page(page,wrapper);
    }
}
